﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/MapPageSiteMaster.Master"
    Inherits="System.Web.Mvc.ViewPage<Micrhard.FMCG.Server.Models.SubKAModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    门店位置设置
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <%using (Html.BeginForm("SaveSubKALocation", "SubKA", FormMethod.Post))
      {
    %>
    <div class="section-header">
        <div class="title">
            <img src="<%=Url.Content("~/Content/images/ico-catalog.png")%>" alt="" />
            门店位置设置
        </div>
        <div class="options">
            <input type="button" id="btnQuery" value="查询" class="t-button" />
            <input type="submit" class="t-button" value="保存" name="save" />
        </div>
    </div>
    <%=ViewData["IsSucceed"]%>
    <table class="adminContent">
        <tr>
            <td class="adminTitle">
                城市
            </td>
            <td class="adminData">
                <%=Model.ProvinceDisplayTxt %>,<%=Model.CityDisplayTxt %>
                <%=Html.HiddenFor(m=>m.ProvinceDisplayTxt) %>
                <%=Html.HiddenFor(m => m.CityDisplayTxt)%>
                <%=Html.HiddenFor(m=>m.SubID) %>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                地址
            </td>
            <td class="adminData">
                <%=Html.EditorFor(m=>m.Address)%>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                经度
            </td>
            <td class="adminData">
                <%=Html.EditorFor(m => m.Baidulng)%>
                <%=Html.ValidationMessageFor(m => m.Baidulng)%>
            </td>
        </tr>
        <tr>
            <td class="adminTitle">
                纬度
            </td>
            <td class="adminData">
                <%=Html.EditorFor(m => m.Baidulat)%>
                <%=Html.ValidationMessageFor(m => m.Baidulat)%>
            </td>
        </tr>
    </table>
    <%} %>
    <div id="container">
    </div>
    <script type="text/javascript">
        var previousMarker = null;
        var savedLng = <%=Model.Baidulng%>;
        var savedLat = <%=Model.Baidulat%>;
        $(document).ready(function () {
            var map = new BMap.Map("container");          // 创建地图实例  

            function loadMap(city) {
                map.centerAndZoom(city, 11);                 // 初始化地图，设置中心点坐标和地图级别  
                map.addControl(new BMap.NavigationControl());  //添加默认缩放平移控件
                map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL }));  //右上角，仅包含平移和缩放按钮
                map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_BOTTOM_LEFT, type: BMAP_NAVIGATION_CONTROL_PAN }));  //左下角，仅包含平移按钮
                map.addControl(new BMap.NavigationControl({ anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM }));  //右下角，仅包含缩放按钮
                map.enableScrollWheelZoom();
                if (savedLng > 0 && savedLat > 0) {
                    setSubKA(savedLng, savedLat);
                }
            }

            function setSubKA(lng, lat) {
                if (previousMarker != null) {
                    map.removeOverlay(previousMarker);
                }
                $('#Baidulng').val(lng);
                $('#Baidulat').val(lat);
                var pt = new BMap.Point(lng, lat);
                var myIcon = new BMap.Icon('<%=Url.Content("~/Content/images/trolley.jpg")%>', new BMap.Size(45, 45));
                var marker = new BMap.Marker(pt, { icon: myIcon });  // 创建标注
                map.addOverlay(marker);
                previousMarker = marker;
            }

            function showInfo(e) {
                setSubKA(e.point.lng, e.point.lat);
            }
            map.addEventListener("click", showInfo);

            function showAddress()
            {
                var address = $('#Address').val();
                if (address != '') {
                    var local = new BMap.LocalSearch(map, {
                        renderOptions: { map: map }
                    });
                    local.search(address);
                }
            }

            $('#btnQuery').click(function () {
                showAddress();
            });

            var city = '<%=Model.CityDisplayTxt%>';
            loadMap(city);
        });
    </script>
</asp:Content>
